 local http = require("G_libs.socket.http")
  local ltn12 = require("G_libs.socket.ltn12")
	  local math_random = math.random
  local function get_ran_key()
    math.randomseed(os.time())
    return math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)
  end
  function SendFile(MyUserStr, GameID, FilePath, TimeOut)
    local MyUserStr = MyUserStr or 0
    --sysLog(MyUserStr)
    --do return false end
    GameID = GameID or 1001
    TimeOut = TimeOut or 180
    http.TIMEOUT = timeout
    local files
    local file = io.open(FilePath,"rb")
    sysLog(FilePath)
    if file then
      files = file:read("*a")
      file:close()
    end
    local response_body = {}
    local get_ran_key2=get_ran_key()
    local boundary = "---------------------------7de3a916a0ab0"
    local datatable = {
      "--"..boundary.."\n",
      'Content-Disposition: form-data; name="userStr"\n\n',
      MyUserStr,
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="gameid"\n\n',
      GameID,
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="timeout"\n\n',
      TimeOut,
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="rebate"\n\n',
      "2605|10CAAA2356A7F53F",
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="daili"\n\n',
      "Haoi",
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="kou"\n\n',
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="beizhu"\n\n',
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="ver"\n\n',
      "Web2",
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="key"\n\n',
      get_ran_key2,
      "\n--"..boundary.."\n",
      'Content-Disposition: form-data; name="img"; filename="post.png"\n',
      'Content-Type: image/png\n\n',
      files,
      "\n--"..boundary.."--"
    }
    local data = table.concat(datatable)
    --local data = datatable
    --sysLog(data)
    function get_haoai_url()--这里的获取 url 地址 不对   应该包括 端口号 还有就是需要随机选其中一个服务器
      local res, code = http.request('http://2.haoi23.net/svlist.html')
      if code == 200 then
        local b = string.find(res,":")
        return string.sub(res,4,b+4)
      end
    end
    function get_haoai_url_host()--这里的获取 url 地址 不对   应该包括 端口号 还有就是需要随机选其中一个服务器
      local res, code = http.request('http://2.haoi23.net/svlist.html')
      if code == 200 then
        local b = string.find(res,":")
        return string.sub(res,4,b+4)
      end
    end
    url = -1
    while true do
      url = get_haoai_url()
      if type(url) == "string" then
        break
      else
        sysLog("继续获取网址")
        mSleep(500)
      end
    end
    local post_ = get_haoai_url_host()
    local headers = {
      ["Accept"]= "*/*",
      ["Accept-Language"] = "zh-cn",
      ["Content-Type"] = "multipart/form-data; boundary=---------------------------7de3a916a0ab0",
      ["Host"] = post_ ,
      ["Content-Length"] = #data,
      ["Accept-Encoding"] = "gzip, deflate",
      ["User-Agent"] = "ben",
      ["Connection"] = "Keep-Alive",
      ["Expect"] = "100-continue"
    }
    local rep , code = http.request{
      url = "http://"..url.."/UploadAPI.aspx",
      method = "POST",
      headers = headers  ,
      source = ltn12.source.string(data),
      sink = ltn12.sink.table(response_body),
    }
    return response_body[1]
  end
	function GetPoint(str) 
    local str = 查提分
    local str_ = "User="..查提分.."&r="..get_ran_key()

    local response_body = {}
    local headers = {
      ["Accept"]= "*/*",
      ["Accept-Language"] = "zh-cn",
      ["Content-Type"] = "application/x-www-form-urlencoded",
      ["Host"] = post_ ,
      ["Content-Length"] = #str_,
      ["Accept-Encoding"] = "gzip, deflate",
      ["User-Agent"] = "ben",
      ["Connection"] = "Keep-Alive",
      --["Expect"] = "100-continue"
    }

    local rep , code = http.request{
      url = "http://2.haoi23.net/GetPoint.aspx",
      method = "POST",
      headers = headers  ,
      source = ltn12.source.string(str_),
      sink = ltn12.sink.table(response_body),
    }
return response_body[1]
end
if result1["用谁的"]=="用作者的题分" then
查提分="ljy11111099|82883AF8952CE426"
elseif result1["用谁的"]=="用自己的题分" then
查提分=tostring(密码)
end
function 检测下密码串1()
local aa=0
  while (aa<6) do
	aa=aa+1
	sysLog("开始"..aa)
  mypoint = GetPoint(str)
  mypoint = GetPoint()
   if mypoint == '#密码串有误' then
	 sysLog("结束")
			dialog("您选择了使用自己的好爱题分！！系统检测您填写有误请检测密码串!!!否则不能过老君!!!",0)
			break
			elseif mypoint == '#查询频繁' then
			break
    elseif type(mypoint) == "string" and result1["用谁的"]=="用自己的题分"  then
		sysLog("结束")
      sysLog("现在题分是剩余量是："..mypoint)
      dialog("现在题分是剩余量是："..mypoint,10)
			break
    elseif type(mypoint) == "string" then
		sysLog("结束")
			break
    else
      mSleep(500)
      sysLog("继续查提分")
    end
		
  end
	if result1["显示提分"]["时时显示剩余提分（如果使用的作者提分此功能选择无效）"] == true and result1["用谁的"]=="用自己的题分"  then
	提分显示("剩余题分:"..mypoint)
	end
	end
function 检测下密码串()
for i=1,10 do
  sysLog("开始")
  mypoint = GetPoint(str)
  mypoint = GetPoint()
  mSleep(200)
  if mypoint == '#密码串有误' then
    sysLog("结束")
    mSleep(200)
    vibrator()
    mSleep(200)
    dialog("密码串有误；请重新填写",0)
    mSleep(200)
  elseif mypoint == '#网络错误' then
    sysLog("结束")
    mSleep(200)
    vibrator()
    mSleep(200)
    dialog("网络错误；请检查！",0)
    mSleep(200)
  elseif type(mypoint) == "string" then
    sysLog("结束")
    mSleep(200)
    dialog("您所剩题分为："..mypoint.."请保持充足题分",0)
    break
  else
    mSleep(500)
    sysLog("继续查题分")
  end

end
	if result1["显示提分"]["时时显示剩余提分（如果使用的作者提分此功能选择无效）"] == true and result1["用谁的"]=="用自己的题分"  then
	提分显示("剩余题分:"..mypoint)
	end	
end
